package Thread;

import java.util.Random;

public class FirstThread {
    private static class MyThread extends Thread{
        //run方法是线程的核心工作方法，线程的所有工作都在run方法里面实现
        @Override
        public void run() {
            Random random=new Random();
            while (true){
                //打印线程的名称
                System.out.println(Thread.currentThread().getName());
                //当前线程随机暂停0~9秒
                try {
                    Thread.sleep(random.nextInt(10));
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        public static void main(String[] args) {
            //创建3个线程对象
            MyThread m1=new MyThread();
            MyThread m2=new MyThread();
            MyThread m3=new MyThread();
            //启动线程
            m1.start();
            m2.start();
            m3.start();

            Random random=new Random();
            while (true){
                //打印线程的名称
                System.out.println(Thread.currentThread().getName());
                //当前线程随机暂停0~9秒
                try {
                    Thread.sleep(random.nextInt(10));
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
